package Common_String_API;

public class test1 {
    public static void main(String[] args) {
        String s = "abcdef";
        System.out.println(s.length());//该数组的长度
        System.out.println(s.charAt(5));//提取该索引中的字符

        System.out.println("===================");

        //1.字符串的遍历
        //charAt(i)把索引为i的字符提取出来
        for (int i = 0; i < s.length(); i++) {
            System.out.print(s.charAt(i)+" ");
        }
        System.out.println();

        System.out.println("===================");

        //2.把字符串转化为字符数组,之后可以实现遍历数组来实现遍历字符串
        char[] arr = s.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();

        System.out.println("===================");

        //3.判断字符串内容,内容一样就返回true
        String s1 = new String( "heima");
        String s2 = new String( "heima");
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));//判断字符串内容要用equals,和c语言一样不能直接比较

        System.out.println("===================");

        //4.忽略大小写比较字符串内容,多用于验证码的比较
        String c1 = "12AB34";
        String c2 = "12ab34";
        System.out.println(c1.equals(c2));//false
        System.out.println(c1.equalsIgnoreCase(c2));//true

        System.out.println("==================");

        //5.截取字符串内容(包前不包后)
        String s3 = "abcdefg";
        System.out.println(s3.substring(1, 5));//结果为bcde(包1,不包5即1到四)

        System.out.println("==================");

        //6.从当前索引位置一直截取到结尾
        System.out.println(s3.substring(1));//结果为bcdefg

        System.out.println("==================");

        //7.把字符串中的某个内容替换为新内容,并返回新的字符串队对象
        String info = "垃圾电影";
        String NewInfo = info.replace("垃圾","**");//返回新的字符串
        System.out.println(NewInfo);//结果为**电影

        System.out.println("==================");

        //8.判断字符串中是否含有某个关键字
        String info2 = "java是语言";
        System.out.println(info2.contains("java"));//ture
        System.out.println(info2.contains("jaa"));//false

        System.out.println("==================");

        //9.判断字符串中是否以某个字符开头
        String info3 = "努力奋斗";
        System.out.println(info3.startsWith("努"));//true
        System.out.println(info3.startsWith("努力"));//true
        System.out.println(info3.startsWith("努奋"));//false

        System.out.println(info3.startsWith("努"));//true

        //10.把字符串按照某个指定内容分割成多个字符串,放到一个字符串数组中返回
        String info4 = "a,b,c,d";
        String[] arr1 = info4.split(",");
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
